import { createRouter, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css';

import createRouteGuard from './guard';

export const DEFAULT_LAYOUT = () => import('@/layout/default-layout.vue');

NProgress.configure({ showSpinner: false }); // NProgress Configuration

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: 'login',
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/pages/login/index.vue'),
    },
    {
      path: '/dashboard',
      name: 'Dashboard',
      component: DEFAULT_LAYOUT,
      meta: {
        title: '仪表盘',
        icon: 'icon-dashboard',
        order: 0,
      },
      children: [
        {
          path: 'workplace',
          name: 'Workplace',
          component: () => import('@/pages/dashboard/workplace/index.vue'),
          meta: {
            title: '工作台',
          },
        },
      ],
    },
  ],
  scrollBehavior() {
    return { top: 0 };
  },
});

createRouteGuard(router);

export default router;
